<?php

namespace common\models\work;

use Yii;

/**
 * This is the model class for table "{{%voltage}}".
 *
 * @property int $id
 * @property string $name 等级名称
 * @property int $volt 伏特数值
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class Voltage extends \common\db\ActiveRecord {

    /**
     * 状态
     */
    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%voltage}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['name'], 'required'],
            [['volt', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['name'], 'string', 'max' => 100],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'name' => '等级名称',
            'volt' => '伏特数值',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public static function getOptionsList() {
        $data = static::find()->active(static::STATUS_ACTIVE)->orderBy([
            'volt' => SORT_ASC
        ])->all();

        $levels = [];
        foreach ($data as $item) {
            $levels[] = [
                'id' => $item->id,
                'name' => $item->name,
            ];
        }
        return $levels;
    }

}
